package cn.zmwh.im.server.modules.ums.controller;


import cn.hutool.core.bean.BeanUtil;
import cn.zmwh.im.server.api.Result;
import cn.zmwh.im.server.constant.Constants;
import cn.zmwh.im.server.modules.ums.pojo.entity.ImUser;
import cn.zmwh.im.server.modules.ums.pojo.request.Black2ListRequest;
import cn.zmwh.im.server.modules.ums.pojo.request.FriendAddRequest;
import cn.zmwh.im.server.modules.ums.pojo.request.FriendPassRequest;
import cn.zmwh.im.server.modules.ums.pojo.vo.FriendVO;
import cn.zmwh.im.server.modules.ums.service.ImFriendService;
import cn.zmwh.im.server.modules.ums.service.ImUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * <p>
 * 好友 前端控制器
 * </p>
 *
 * @author dmzmwh
 * @since 2025-06-19
 */
@RestController
@RequestMapping("/api/ums/friend")
public class ImFriendController {

    @Autowired
    private ImFriendService imFriendService;

    @Autowired
    private ImUserService imUserService;


    @GetMapping("/list")
    @ApiOperation(value = "好友列表")
    public Result<List<FriendVO>> list(@ApiIgnore @RequestHeader(Constants.UID) Long uid) {

        return imFriendService.listByUid(uid);
    }


    @GetMapping("/{friendId}")
    @ApiOperation(value = "好友列表")
    public Result<FriendVO> id(@PathVariable Long friendId) {
        FriendVO vo = new FriendVO();
        ImUser byId = imUserService.getById(friendId);
        BeanUtil.copyProperties(byId,vo);
        return Result.ok(vo);
    }


    @PostMapping("/add")
    @ApiOperation(value = "添加好友 ")
    public Result addFriend(@RequestBody FriendAddRequest request) {
        return imFriendService.addFriend(request);
    }

    @PostMapping("/pass")
    @ApiOperation(value = "通过好友 ")
    public Result passFriend(@RequestBody FriendPassRequest request) {
        imFriendService.passFriend(request);
        return Result.success();
    }


    @PostMapping("/black2list")
    @ApiOperation(value = "拉黑好友 ")
    public Result black2list(@RequestBody Black2ListRequest request) {
        imFriendService.black2list(request);
        return Result.success();
    }


    @DeleteMapping("/delete/{friendId}")
    @ApiOperation(value = "删除好友")
    public Result delFriend(@PathVariable Long friendId, @ApiIgnore @RequestHeader(Constants.UID) Long uid) {
        imFriendService.delFriend(friendId, uid);
        return Result.success();
    }


}

